/**
 *
 */
package com.naiterui.ehp.bs.doctor.utils;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.utils.lang.ConfigUtil;
import com.naiterui.ehp.bp.utils.net.RestHttpUtil;

/**
 * push发送公共类
 * @author fangguanhong
 * @since 1.0.0
 */
public class PushUtil {

    private static final Logger LOGGER = LoggerFactory.getLogger(PushUtil.class);

    /** push发送调用服务地址 */
    public static final String PUSH_MESSAGE_SERVER = ConfigUtil.getString("push.message.server");

    /**
     * 指定用户发送push
     */
    public static void pushMessage(Long userId, String pushMessage, String linkUrl, UserType userType) throws BusinessException {
        LOGGER.info("[push]指定用户发送push处理，直接请求messageServer，参数为：" + userId + ";" + pushMessage + ";" + linkUrl + ";" + userType);
        Map<String, String> params = new HashMap<>();
        if (userType == UserType.DOCTOR) {
            params.put("userType", "d");
        } else {
            params.put("userType", "p");
        }
        params.put("userId", userId + "");
        params.put("pushMessage", pushMessage);
        params.put("linkUrl", linkUrl);
        LOGGER.error("[push]调用MessageServer指定用户发送push接口参数地址：" + PushUtil.PUSH_MESSAGE_SERVER + ";参数为：" + params);
        RestHttpUtil.post().url(PushUtil.PUSH_MESSAGE_SERVER).paramMap(params).executeData();
    }

}
